import wx
import os
import sys
import random, struct
from Crypto.Cipher import AES
from tkMessageBox import *
import wx.lib.sized_controls as sc

try:
    dirName = os.path.dirname(os.path.abspath(__file__))
except:
    dirName = os.path.dirname(os.path.abspath(sys.argv[0]))

sys.path.append(os.path.split(dirName)[0])

try:
    from agw import buttonpanel as bp
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.buttonpanel as bp

try:
    from agw import gradientbutton as GB
    bitmapDir = "bitmaps/"
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.gradientbutton as GB
    bitmapDir = "agw/bitmaps/"  

try:
    from agw import knobctrl as KC
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.knobctrl as KC

try:
    from agw import multidirdialog as MDD
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.multidirdialog as MDD    

import images
import random

#----------------------------------------------------------------------

ID_BackgroundColour = wx.NewId()
ID_GradientFrom = wx.NewId()
ID_GradientTo = wx.NewId()
ID_BorderColour = wx.NewId()
ID_CaptionColour = wx.NewId()
ID_ButtonTextColour = wx.NewId()
ID_SelectionBrush = wx.NewId()
ID_SelectionPen = wx.NewId()
ID_SeparatorColour = wx.NewId()


#----------------------------------------------------------------------

def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
    if not out_filename:
        
        out_filename = in_filename[:-4] + '.enc'

    iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    filesize = os.path.getsize(in_filename)

    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', filesize))
            outfile.write(iv)
            print "64 bit-AES-ENCRYPTING UTILITY :- credit: Ashutosh Chaudhary a.k.a ashurocks\nPlease wait...encryption under progress..DO NOT CANCEL"

            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += ' ' * (16 - len(chunk) % 16)
                outfile.write(encryptor.encrypt(chunk))


#------------------------------------------------------------------------
                

def decrypt_file(key, in_filename, out_filename=None, chunksize=24*1024):
    """ Decrypts a file using AES (CBC mode) with the
        given key. Parameters are similar to encrypt_file,
        with one difference: out_filename, if not supplied
        will be in_filename without its last extension
        (i.e. if in_filename is 'aaa.zip.enc' then
        out_filename will be 'aaa.zip')
    """
    if not out_filename:
        out_filename = os.path.splitext(in_filename)[0]

    with open(in_filename, 'rb') as infile:
        origsize = struct.unpack('<Q', infile.read(struct.calcsize('Q')))[0]
        iv = infile.read(16)
        decryptor = AES.new(key, AES.MODE_CBC, iv)

        with open(out_filename, 'wb') as outfile:
            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                outfile.write(decryptor.decrypt(chunk))
            print "64 bit-AES-DECRYPTING UTILITY :- credit: Ashutosh Chaudhary a.k.a ashurocks\nPlease wait...decryption under progress..DO NOT CANCEL"
            outfile.truncate(origsize)


key="ashulovespreranaashulovesprerana"
            
#----------------------------------------------------------------------------------------

class FormDialog(sc.SizedDialog):
    def __init__(self, parent, id):
        sc.SizedDialog.__init__(self, None, -1, "Password Changer", 
                        style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        
        pane = self.GetContentsPane()
        pane.SetSizerType("form")
        global textCtrl, emailCtrl
        
        # row 1
        wx.StaticText(pane, -1, "Enter new password\t")
        textCtrl = wx.TextCtrl(pane, -1, "",style=wx.TE_PASSWORD)
        textCtrl.SetSizerProps(expand=True)
        
        # row 2
        wx.StaticText(pane, -1, "Enter it again\t")
        emailCtrl = wx.TextCtrl(pane, -1, "",style=wx.TE_PASSWORD)
        emailCtrl.SetSizerProps(expand=True)
        
        
        # add dialog buttons
        self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL))
        
        # a little trick to make sure that you can't resize the dialog to
        # less screen space than the controls need
        self.Fit()
        self.SetMinSize(self.GetSize())

#-----------------------------------------------------------------------------------
        
            
class SettingsPanel(wx.MiniFrame):

    def __init__(self, parent="None", id=wx.ID_ANY, title="Settings Panel", pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.FRAME_NO_TASKBAR
                 | wx.FRAME_FLOAT_ON_PARENT | wx.CLIP_CHILDREN):

        wx.MiniFrame.__init__(self, parent, id, title, pos, size, style)

        self.targetTitleBar = parent.titleBar
        self.parent = parent
        self.panel = wx.Panel(self, -1)
        
        self.coloursizer_staticbox = wx.StaticBox(self.panel, -1, "Colour Options")
        self.bottomsizer_staticbox = wx.StaticBox(self.panel, -1, "Size Options")
        self.stylesizer_staticbox = wx.StaticBox(self.panel, -1, "Orintal Styles")
        self.defaultstyle = wx.RadioButton(self.panel, -1, "Default Style", style=wx.RB_GROUP)
        self.gradientstyle = wx.RadioButton(self.panel, -1, "Gradient Style")
        self.verticalgradient = wx.RadioButton(self.panel, -1, "Vertical Gradient", style=wx.RB_GROUP)
        self.horizontalgradient = wx.RadioButton(self.panel, -1, "Horizontal Gradient")

        b = self.CreateColourBitmap(wx.BLACK)
        
        self.bakbrush = wx.BitmapButton(self.panel, ID_BackgroundColour, b, size=wx.Size(50,25))
        self.gradientfrom = wx.BitmapButton(self.panel, ID_GradientFrom, b, size=wx.Size(50,25))
        self.gradientto = wx.BitmapButton(self.panel, ID_GradientTo, b, size=wx.Size(50,25))
        self.bordercolour = wx.BitmapButton(self.panel, ID_BorderColour, b, size=wx.Size(50,25))
        self.captioncolour = wx.BitmapButton(self.panel, ID_CaptionColour, b, size=wx.Size(50,25))
        self.textbuttoncolour = wx.BitmapButton(self.panel, ID_ButtonTextColour, b, size=wx.Size(50,25))
        self.selectionbrush = wx.BitmapButton(self.panel, ID_SelectionBrush, b, size=wx.Size(50,25))
        self.selectionpen = wx.BitmapButton(self.panel, ID_SelectionPen, b, size=wx.Size(50,25))
        self.separatorcolour = wx.BitmapButton(self.panel, ID_SeparatorColour, b, size=wx.Size(50,25))

        self.separatorspin = wx.SpinCtrl(self.panel, -1, "7", min=3, max=20,
                                         style=wx.SP_ARROW_KEYS)
        self.marginspin = wx.SpinCtrl(self.panel, -1, "6", min=3, max=20,
                                      style=wx.SP_ARROW_KEYS)
        self.paddingspin = wx.SpinCtrl(self.panel, -1, "6", min=3, max=10,
                                       style=wx.SP_ARROW_KEYS)
        self.borderspin = wx.SpinCtrl(self.panel, -1, "3", min=3, max=7,
                                      style=wx.SP_ARROW_KEYS)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_RADIOBUTTON, self.OnDefaultStyle, self.defaultstyle)
        self.Bind(wx.EVT_RADIOBUTTON, self.OnGradientStyle, self.gradientstyle)
        self.Bind(wx.EVT_RADIOBUTTON, self.OnVerticalGradient, self.verticalgradient)
        self.Bind(wx.EVT_RADIOBUTTON, self.OnHorizontalGradient, self.horizontalgradient)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_BackgroundColour)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_GradientFrom)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_GradientTo)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_BorderColour)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_CaptionColour)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_ButtonTextColour)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SelectionBrush)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SelectionPen)
        self.Bind(wx.EVT_BUTTON, self.OnSetColour, id=ID_SeparatorColour)
        
        self.Bind(wx.EVT_SPINCTRL, self.OnSeparator, self.separatorspin)
        self.Bind(wx.EVT_SPINCTRL, self.OnMargins, self.marginspin)
        self.Bind(wx.EVT_SPINCTRL, self.OnPadding, self.paddingspin)
        self.Bind(wx.EVT_SPINCTRL, self.OnBorder, self.borderspin)

        self.Bind(wx.EVT_CLOSE, self.OnClose)        


    def __set_properties(self):

        self.defaultstyle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.defaultstyle.SetValue(1)
        self.gradientstyle.SetFont(wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.verticalgradient.SetValue(1)

        if self.targetTitleBar.GetStyle() & bp.BP_DEFAULT_STYLE:
            self.verticalgradient.Enable(False)
            self.horizontalgradient.Enable(False)
            self.defaultstyle.SetValue(1)
        else:
            self.gradientstyle.SetValue(1)

        self.borderspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_BORDER_SIZE))
        self.separatorspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_SEPARATOR_SIZE))
        self.marginspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_MARGINS_SIZE).x)
        self.paddingspin.SetValue(self.targetTitleBar.GetBPArt().GetMetric(bp.BP_PADDING_SIZE).x)

        self.UpdateColours()        
        

    def __do_layout(self):

        mainsizer = wx.BoxSizer(wx.VERTICAL)
        buttonsizer = wx.BoxSizer(wx.HORIZONTAL)
        bottomsizer = wx.StaticBoxSizer(self.bottomsizer_staticbox, wx.VERTICAL)
        sizer_13 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_11 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
        coloursizer = wx.StaticBoxSizer(self.coloursizer_staticbox, wx.HORIZONTAL)
        rightsizer = wx.BoxSizer(wx.VERTICAL)
        sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_7 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
        leftsizer = wx.BoxSizer(wx.VERTICAL)
        sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
        stylesizer = wx.StaticBoxSizer(self.stylesizer_staticbox, wx.VERTICAL)
        tophsizer = wx.BoxSizer(wx.HORIZONTAL)
        tophsizer2 = wx.BoxSizer(wx.VERTICAL)
        
        stylesizer.Add(self.defaultstyle, 0, wx.ALL|wx.EXPAND|wx.ADJUST_MINSIZE, 5)

        tophsizer.Add(self.gradientstyle, 0, wx.LEFT|wx.RIGHT|wx.EXPAND|
                      wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)

        tophsizer2.Add(self.verticalgradient, 0, wx.BOTTOM|wx.ADJUST_MINSIZE, 3)
        tophsizer2.Add(self.horizontalgradient, 0, wx.ADJUST_MINSIZE, 0)
        
        tophsizer.Add(tophsizer2, 1, wx.LEFT|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 10)

        stylesizer.Add(tophsizer, 1, wx.EXPAND, 0)

        mainsizer.Add(stylesizer, 0, wx.ALL|wx.EXPAND, 5)

        label_1 = wx.StaticText(self.panel, -1, "Background Brush Colour:")
        sizer_1.Add(label_1, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_1.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_1.Add(self.bakbrush, 0, wx.ADJUST_MINSIZE, 0)

        leftsizer.Add(sizer_1, 1, wx.EXPAND, 0)

        label_2 = wx.StaticText(self.panel, -1, "Gradient Colour From:")
        sizer_2.Add(label_2, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_2.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_2.Add(self.gradientfrom, 0, wx.ADJUST_MINSIZE, 0)

        leftsizer.Add(sizer_2, 1, wx.EXPAND, 0)

        label_3 = wx.StaticText(self.panel, -1, "Gradient Colour To:")
        sizer_3.Add(label_3, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_3.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_3.Add(self.gradientto, 0, wx.ADJUST_MINSIZE, 0)

        leftsizer.Add(sizer_3, 1, wx.EXPAND, 0)

        label_4 = wx.StaticText(self.panel, -1, "Border Colour:")
        sizer_4.Add(label_4, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_4.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_4.Add(self.bordercolour, 0, wx.ADJUST_MINSIZE, 0)

        leftsizer.Add(sizer_4, 1, wx.EXPAND, 0)

        label_5 = wx.StaticText(self.panel, -1, "Main Caption Colour:")
        sizer_5.Add(label_5, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_5.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_5.Add(self.captioncolour, 0, wx.ADJUST_MINSIZE, 0)

        leftsizer.Add(sizer_5, 1, wx.EXPAND, 0)

        coloursizer.Add(leftsizer, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)
        coloursizer.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        
        label_6 = wx.StaticText(self.panel, -1, "Text Button Colour:")
        sizer_6.Add(label_6, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_6.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_6.Add(self.textbuttoncolour, 0, wx.ADJUST_MINSIZE, 0)

        rightsizer.Add(sizer_6, 1, wx.EXPAND, 0)

        label_7 = wx.StaticText(self.panel, -1, "Selection Brush Colour:")
        sizer_7.Add(label_7, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_7.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_7.Add(self.selectionbrush, 0, wx.ADJUST_MINSIZE, 0)

        rightsizer.Add(sizer_7, 1, wx.EXPAND, 0)

        label_8 = wx.StaticText(self.panel, -1, "Selection Pen Colour:")
        sizer_8.Add(label_8, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_8.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_8.Add(self.selectionpen, 0, wx.ADJUST_MINSIZE, 0)

        rightsizer.Add(sizer_8, 1, wx.EXPAND, 0)

        label_9 = wx.StaticText(self.panel, -1, "Separator Colour:")
        sizer_9.Add(label_9, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_9.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_9.Add(self.separatorcolour, 0, wx.ADJUST_MINSIZE, 0)

        rightsizer.Add(sizer_9, 1, wx.EXPAND, 0)

        coloursizer.Add(rightsizer, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5)

        mainsizer.Add(coloursizer, 0, wx.ALL|wx.EXPAND, 5)

        label_10 = wx.StaticText(self.panel, -1, "Separator Size:")
        sizer_10.Add(label_10, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_10.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_10.Add(self.separatorspin, 0, wx.ALL|wx.ADJUST_MINSIZE, 5)

        bottomsizer.Add(sizer_10, 1, wx.EXPAND, 0)

        label_11 = wx.StaticText(self.panel, -1, "Margins Size:")
        sizer_11.Add(label_11, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_11.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_11.Add(self.marginspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)

        bottomsizer.Add(sizer_11, 1, wx.EXPAND, 0)

        label_12 = wx.StaticText(self.panel, -1, "Padding Size:")
        sizer_12.Add(label_12, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_12.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_12.Add(self.paddingspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)

        bottomsizer.Add(sizer_12, 1, wx.EXPAND, 0)

        label_13 = wx.StaticText(self.panel, -1, "Border Size:")
        sizer_13.Add(label_13, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 5)
        sizer_13.Add((0, 0), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        sizer_13.Add(self.borderspin, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.ADJUST_MINSIZE, 5)

        bottomsizer.Add(sizer_13, 1, wx.EXPAND, 0)

        mainsizer.Add(bottomsizer, 0, wx.ALL|wx.EXPAND, 5)

        self.panel.SetSizer(mainsizer)
        sizer = wx.BoxSizer()
        sizer.Add(self.panel, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Fit()


    def CreateColourBitmap(self, c):
    
        image = wx.EmptyImage(25, 14)
        
        for x in xrange(25):
            for y in xrange(14):
                pixcol = c
                if x == 0 or x == 24 or y == 0 or y == 13:
                    pixcol = wx.BLACK
                    
                image.SetRGB(x, y, pixcol.Red(), pixcol.Green(), pixcol.Blue())
            
        return image.ConvertToBitmap()


    def UpdateColours(self):
    
        bk = self.targetTitleBar.GetBPArt().GetColour(bp.BP_BACKGROUND_COLOUR)
        self.bakbrush.SetBitmapLabel(self.CreateColourBitmap(bk))
        
        capfrom = self.targetTitleBar.GetBPArt().GetColour(bp.BP_GRADIENT_COLOUR_FROM)
        self.gradientfrom.SetBitmapLabel(self.CreateColourBitmap(capfrom))

        capto = self.targetTitleBar.GetBPArt().GetColour(bp.BP_GRADIENT_COLOUR_TO)
        self.gradientto.SetBitmapLabel(self.CreateColourBitmap(capto))

        captxt = self.targetTitleBar.GetBPArt().GetColour(bp.BP_TEXT_COLOUR)
        self.captioncolour.SetBitmapLabel(self.CreateColourBitmap(captxt))

        bor = self.targetTitleBar.GetBPArt().GetColour(bp.BP_BORDER_COLOUR)
        self.bordercolour.SetBitmapLabel(self.CreateColourBitmap(bor))
        
        btntext = self.targetTitleBar.GetBPArt().GetColour(bp.BP_BUTTONTEXT_COLOUR)
        self.textbuttoncolour.SetBitmapLabel(self.CreateColourBitmap(btntext))

        selb = self.targetTitleBar.GetBPArt().GetColour(bp.BP_SELECTION_BRUSH_COLOUR)
        self.selectionbrush.SetBitmapLabel(self.CreateColourBitmap(selb))

        selp = self.targetTitleBar.GetBPArt().GetColour(bp.BP_SELECTION_PEN_COLOUR)
        self.selectionpen.SetBitmapLabel(self.CreateColourBitmap(selp))
        
        sepc = self.targetTitleBar.GetBPArt().GetColour(bp.BP_SEPARATOR_COLOUR)
        self.separatorcolour.SetBitmapLabel(self.CreateColourBitmap(sepc))


    def OnDefaultStyle(self, event):

        self.verticalgradient.Enable(False)
        self.horizontalgradient.Enable(False)
        self.targetTitleBar.SetStyle(bp.BP_DEFAULT_STYLE)

        self.targetTitleBar.Refresh()

        event.Skip()
        

    def OnGradientStyle(self, event): 

        self.verticalgradient.Enable(True)
        self.horizontalgradient.Enable(True)
        self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
        self.targetTitleBar.Refresh()
        
        event.Skip()


    def OnVerticalGradient(self, event):

        self.targetTitleBar.GetBPArt().SetGradientType(bp.BP_GRADIENT_VERTICAL)
        self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
        self.targetTitleBar.Refresh()
        
        event.Skip()
        

    def OnHorizontalGradient(self, event):

        self.targetTitleBar.GetBPArt().SetGradientType(bp.BP_GRADIENT_HORIZONTAL)
        self.targetTitleBar.SetStyle(bp.BP_USE_GRADIENT)
        self.targetTitleBar.Refresh()
        
        event.Skip()
        

    def OnSetColour(self, event):

        dlg = wx.ColourDialog(self.parent)
        
        dlg.SetTitle("Colour Picker")
        
        if dlg.ShowModal() != wx.ID_OK:
            return
        
        var = 0
        if event.GetId() == ID_BackgroundColour:
            var = bp.BP_BACKGROUND_COLOUR
        elif event.GetId() == ID_GradientFrom:
            var = bp.BP_GRADIENT_COLOUR_FROM
        elif event.GetId() == ID_GradientTo:
            var = bp.BP_GRADIENT_COLOUR_TO
        elif event.GetId() == ID_BorderColour:
            var = bp.BP_BORDER_COLOUR
        elif event.GetId() == ID_CaptionColour:
            var = bp.BP_TEXT_COLOUR
        elif event.GetId() == ID_ButtonTextColour:
            var = bp.BP_BUTTONTEXT_COLOUR
        elif event.GetId() == ID_SelectionBrush:
            var = bp.BP_SELECTION_BRUSH_COLOUR
        elif event.GetId() == ID_SelectionPen:
            var = bp.BP_SELECTION_PEN_COLOUR
        elif event.GetId() == ID_SeparatorColour:
            var = bp.BP_SEPARATOR_COLOUR
        else:
            return        
        
        self.targetTitleBar.GetBPArt().SetColour(var, dlg.GetColourData().GetColour())
        self.targetTitleBar.Refresh()
        self.UpdateColours()

        self.parent.useredited = True


    def OnSeparator(self, event):

        self.targetTitleBar.GetBPArt().SetMetric(bp.BP_SEPARATOR_SIZE,
                                                 event.GetInt())

        self.targetTitleBar.DoLayout()
        self.parent.mainPanel.Layout()
        self.parent.useredited = True

        event.Skip()


    def OnMargins(self, event):

        self.targetTitleBar.GetBPArt().SetMetric(bp.BP_MARGINS_SIZE,
                                                 wx.Size(event.GetInt(), event.GetInt()))

        self.targetTitleBar.DoLayout()
        self.parent.mainPanel.Layout()

        self.parent.useredited = True
        
        event.Skip()


    def OnPadding(self, event):

        self.targetTitleBar.GetBPArt().SetMetric(bp.BP_PADDING_SIZE,
                                                 wx.Size(event.GetInt(), event.GetInt()))

        self.targetTitleBar.DoLayout()
        self.parent.mainPanel.Layout()
        self.parent.useredited = True
        
        event.Skip()


    def OnBorder(self, event):

        self.targetTitleBar.GetBPArt().SetMetric(bp.BP_BORDER_SIZE,
                                                 event.GetInt())

        self.targetTitleBar.DoLayout()
        self.parent.mainPanel.Layout()

        self.parent.useredited = True
        
        event.Skip()


    def OnClose(self, event):

        self.parent.hassettingpanel = False
        self.Destroy()


#----------------------------------------------------------------------

class ButtonPanelDemo(wx.Frame):

    def __init__(self, parent="None", id=wx.ID_ANY, title="Advanced Folder Locker ;-)",
                 pos=wx.DefaultPosition, size=(640, 400), style=wx.DEFAULT_FRAME_STYLE):
        
        wx.Frame.__init__(self, None, id, title, pos, size, style)

        self.useredited = False
        self.hassettingpanel = False

        self.SetIcon(images.Mondrian.GetIcon())
        self.CreateMenuBar()

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-2, -1])
        # statusbar fields
        statusbar_fields = [("Advanced Folder Locker by Ashutosh Chaudhary a.k.a @shurockss "),
                            ("Enjoy my software!")]

        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        
        self.mainPanel = wx.Panel(self, -1)
        
        
        vSizer = wx.BoxSizer(wx.VERTICAL) 
        self.mainPanel.SetSizer(vSizer) 

        self.alignments = [bp.BP_ALIGN_LEFT, bp.BP_ALIGN_RIGHT, bp.BP_ALIGN_TOP, bp.BP_ALIGN_BOTTOM]
        
        self.alignment = bp.BP_ALIGN_LEFT
        self.agwStyle = bp.BP_USE_GRADIENT
        
        self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "Advanced Folder Locker",
                                       agwStyle=self.agwStyle, alignment=self.alignment)

        self.created = False
        self.pngs = [ 
                      (images._bp_btn2.GetBitmap(), 'Next Step'),
                      
                      ]
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.CreateButtons()
        self.SetProperties()
                
        
    def CreateMenuBar(self):
        global mb
        mb = wx.MenuBar()
        global file_menu
        file_menu = wx.Menu()
        
        item = wx.MenuItem(file_menu, wx.ID_ANY, "&Change Password")
        file_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnCloseit, item)

        edit_menu = wx.Menu()

        item = wx.MenuItem(edit_menu, wx.ID_ANY, "Set Header")
        edit_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnSetBarText, item)

        edit_menu.AppendSeparator()        

                
        submenu = wx.Menu()

        item = wx.MenuItem(submenu, wx.ID_ANY, "Default Style", kind=wx.ITEM_RADIO)
        submenu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnDefaultStyle, item)
        
        item = wx.MenuItem(submenu, wx.ID_ANY, "Gradient Style", kind=wx.ITEM_RADIO)
        submenu.AppendItem(item)
        item.Check(True)
        self.Bind(wx.EVT_MENU, self.OnGradientStyle, item)
        
        edit_menu.AppendMenu(wx.ID_ANY, "&Styles", submenu)

        edit_menu.AppendSeparator()
        
        item = wx.MenuItem(submenu, wx.ID_ANY, "Settings Panel")
        edit_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnSettingsPanel, item)

        demo_menu = wx.Menu()
        
        item = wx.MenuItem(demo_menu, wx.ID_ANY, "Default Demo", kind=wx.ITEM_RADIO)
        demo_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnDefaultDemo, item)

        item = wx.MenuItem(demo_menu, wx.ID_ANY, "Button Only Demo", kind=wx.ITEM_RADIO)
        demo_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnButtonOnly, item)
        
        help_menu = wx.Menu()

        item = wx.MenuItem(help_menu, wx.ID_ANY, "&About...")
        help_menu.AppendItem(item)
        self.Bind(wx.EVT_MENU, self.OnAbout, item)
      
        mb.Append(file_menu, "&File")
        mb.Append(edit_menu, "&Edit")
        mb.Append(help_menu, "&Help")
        mb.Remove(0)
        self.SetMenuBar(mb)

    def OnCloseit(self, event):
        dlg = FormDialog(self, -1)
        dlg.CenterOnScreen()
        # this does not return until the dialog is closed.
        val = dlg.ShowModal()
        asc=textCtrl.GetValue()
        bsc=emailCtrl.GetValue() 
        if val == wx.ID_OK:
            if (asc==bsc):
                if (asc==''):
                    dlgg = wx.MessageDialog(self, "Blank Passwords are not allowed", "Error",
                               wx.OK | wx.ICON_INFORMATION)
                    dlgg.ShowModal()
                    dlgg.Destroy()
                else:
                    try:
                        os.remove("def.enc")
                    except:
                        pass
                    passw=open("def.dll","w")
                    passw.write(asc)
                    passw.close()
                    encrypt_file(key, "def.dll")
                    os.remove("def.dll")
                    dlgg = wx.MessageDialog(self, "Password changed successfully", "Successfull",
                               wx.OK | wx.ICON_INFORMATION)
                    dlgg.ShowModal()
                    dlgg.Destroy()
            else:
                dlgg = wx.MessageDialog(self, "Password not matched\nRe-enter password", "Failed",
                               wx.OK | wx.ICON_INFORMATION)
                dlgg.ShowModal()
                dlgg.Destroy()
        else:
            pass

        dlg.Destroy()
        dlg.Destroy()
        


    def CreateButtons(self):

        # Here we (re)create the buttons for the default startup demo
        self.Freeze()

        if self.created:
            sizer = self.mainPanel.GetSizer()
            sizer.Detach(0)
            self.titleBar.Hide()
            wx.CallAfter(self.titleBar.Destroy)
            self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "Advanced Folder Locker",
                                           agwStyle=self.agwStyle, alignment=self.alignment)
            self.SetProperties()
                    
        self.indices = []
        
        for count, png in enumerate(self.pngs):

            shortHelp = "next wizard"
            
            if count < 2:
                # First 2 buttons are togglebuttons
                kind = wx.ITEM_CHECK
                longHelp = "Goto next wizard"
            else:
                kind = wx.ITEM_NORMAL
                longHelp = "Goto next wizard"                
            global btn
            btn = bp.ButtonInfo(self.titleBar, wx.NewId(),
                                png[0], kind=kind,
                                shortHelp=shortHelp, longHelp=longHelp)

            btn.Disable()
            self.titleBar.AddButton(btn)
            self.Bind(wx.EVT_BUTTON, self.OnButton)
            
            self.indices.append(btn.GetId())
            
            if count < 2:
                # First 2 buttons have also a text
                btn.SetText(png[1])

            if count == 2:
                # Append a separator after the second button
                self.titleBar.AddSeparator()
            
            if count == 1:
                # Add a wx.TextCtrl to ButtonPanel
                self.titleBar.AddControl(wx.TextCtrl(self.titleBar, -1, "Hello Friends!"))
                btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT)

        # Add a wx.Choice to ButtonPanel                        
                
        self.strings = ["First", "Second", "Third", "Fourth"]

        self.ChangeLayout()              
        self.Thaw()
        self.titleBar.DoLayout()

        self.created = True
        

    def ButtonOnly(self):
        
        # Here we (re)create the buttons for the button-only demo
        self.Freeze()
        
        if self.created:
            sizer = self.mainPanel.GetSizer()
            sizer.Detach(0)
            self.titleBar.Hide()
            wx.CallAfter(self.titleBar.Destroy)
            self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "Advanced Folder Locker",
                                           agwStyle=self.agwStyle, alignment=self.alignment)
            self.SetProperties()

        # Buttons are created completely random, with random images, toggle behavior
        # and text
        
        self.indices = []
        
        for count in xrange(8):

            itemImage = random.randint(0, 3)
            hasText = random.randint(0, 1)
            itemKind = random.randint(0, 1)
                            
            btn = bp.ButtonInfo(self.titleBar, wx.NewId(), self.pngs[itemImage][0],
                                kind=itemKind)

            if hasText:
                btn.SetText(self.pngs[itemImage][1])
                rightText = random.randint(0, 1)
                if rightText:
                    btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT)

            self.titleBar.AddButton(btn)
            self.Bind(wx.EVT_BUTTON, self.OnButton, id=btn.GetId())
            
            self.indices.append(btn.GetId())

            if count in [0, 3, 5]:
                self.titleBar.AddSeparator()
                    
        self.strings = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth"]
        self.ChangeLayout()              
        self.Thaw()
        self.titleBar.DoLayout()
        

    def ChangeLayout(self):
        
        # Change the layout after a switch in ButtonPanel alignment
        self.Freeze()
        
        if self.alignment in [bp.BP_ALIGN_LEFT, bp.BP_ALIGN_RIGHT]:
            vSizer = wx.BoxSizer(wx.VERTICAL)
        else:
            vSizer = wx.BoxSizer(wx.HORIZONTAL)
            
        self.mainPanel.SetSizer(vSizer) 

        vSizer.Add(self.titleBar, 0, wx.EXPAND)
        vSizer.Add((20, 20))
        global ashu
        font = wx.Font(18, wx.DECORATIVE,wx.ITALIC, wx.BOLD)
        ashu=wx.StaticText(self.mainPanel, -1, "Authenticating User",(180, 70))
        ashu.SetFont(font)
        global t2, l2
        l2 = wx.StaticText(self.mainPanel, -1, "Enter Password:",(190,120))
        t2 = wx.TextCtrl(self.mainPanel, -1, "", size=(125, -1),pos=(285,120),style=wx.TE_PASSWORD)
        global button
        button = wx.Button(self.mainPanel, -1, "Proceed", pos=(300,200))
        self.Bind(wx.EVT_BUTTON, self.OnClickpass, button)
        try:
            decrypt_file(key, "def.enc")
        except:
            dlg = wx.MessageDialog(self, "You are trying to run multiple copy of the software.Only one copy is allowed!!!\n\nPlease reinstall", "Error",
                               wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            
            sys.exit()
        global forr
        fop=open("def","r")
        forr=fop.read()
        fop.close()
        os.remove("def")
        vSizer.Layout()
        self.mainPanel.Layout()
        
        self.Thaw()

                
    def OnClickpass(self,event):
        
        t5=t2.GetValue()
        if (t5==forr):
            button.Disable()
            os.system("reg add hklm\\software\\microsoft\\Flk /v oninithold /t reg_sz /f")
            self.mainPanel.Refresh()
            btn.Enable()
            self.OnButton(t5)
            
        else:
            dlg = wx.MessageDialog(self, "Incorrect Password!!!\n\nUNAUTHENTICATED", "Try Again",
                               wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            btn.Disable()
            
        

            
        
        
        
        
    def SetProperties(self):

        # No resetting if the user is using the Settings Panel
        if self.useredited:
            return
        
        # Sets the colours for the two demos: called only if the user didn't
        # modify the colours and sizes using the Settings Panel
        bpArt = self.titleBar.GetBPArt()
        
        if self.agwStyle & bp.BP_USE_GRADIENT:
            # set the colour the text is drawn with
            bpArt.SetColour(bp.BP_TEXT_COLOUR, wx.WHITE)

            # These default to white and whatever is set in the system
            # settings for the wx.SYS_COLOUR_ACTIVECAPTION.  We'll use
            # some specific settings to ensure a consistent look for the
            # demo.
            bpArt.SetColour(bp.BP_BORDER_COLOUR, wx.Colour(120,23,224))
            bpArt.SetColour(bp.BP_GRADIENT_COLOUR_FROM, wx.Colour(60,11,112))
            bpArt.SetColour(bp.BP_GRADIENT_COLOUR_TO, wx.Colour(120,23,224))
            bpArt.SetColour(bp.BP_BUTTONTEXT_COLOUR, wx.Colour(70,143,255))
            bpArt.SetColour(bp.BP_SEPARATOR_COLOUR,
                            bp.BrightenColour(wx.Colour(60, 11, 112), 0.85))
            bpArt.SetColour(bp.BP_SELECTION_BRUSH_COLOUR, wx.Colour(225, 225, 255))
            bpArt.SetColour(bp.BP_SELECTION_PEN_COLOUR, wx.SystemSettings_GetColour(wx.SYS_COLOUR_ACTIVECAPTION))

        else:

            background = self.titleBar.GetBackgroundColour()            
            bpArt.SetColour(bp.BP_TEXT_COLOUR, wx.BLUE)
            bpArt.SetColour(bp.BP_BORDER_COLOUR,
                            bp.BrightenColour(background, 0.85))
            bpArt.SetColour(bp.BP_SEPARATOR_COLOUR,
                            bp.BrightenColour(background, 0.85))
            bpArt.SetColour(bp.BP_BUTTONTEXT_COLOUR, wx.BLACK)
            bpArt.SetColour(bp.BP_SELECTION_BRUSH_COLOUR, wx.Colour(242, 242, 235))
            bpArt.SetColour(bp.BP_SELECTION_PEN_COLOUR, wx.Colour(206, 206, 195))

        self.titleBar.SetStyle(self.agwStyle)
        
        
    def OnAlignment(self, event):
        
        # Here we change the alignment property of ButtonPanel
        current = event.GetId()
        item = self.GetMenuBar().FindItemById(current)
        alignment = getattr(bp, item.GetLabel())
        self.alignment = alignment

        self.ChangeLayout()    
        self.titleBar.SetAlignment(alignment)
        self.mainPanel.Layout()
        
        event.Skip()


    def OnDefaultStyle(self, event):
        
        # Restore the ButtonPanel default style (no gradient)
        self.agwStyle = bp.BP_DEFAULT_STYLE
        
        self.SetProperties()

        event.Skip()        


    def OnGradientStyle(self, event):

        # Use gradients to paint ButtonPanel background
        self.agwStyle = bp.BP_USE_GRADIENT
        self.SetProperties()
        event.Skip()        


    def OnDefaultDemo(self, event):
        
        # Reload the default startup demo
        self.CreateButtons()
        
        event.Skip()


    def OnButtonOnly(self, event):

        # Reload the button-only demo
        self.ButtonOnly()
        event.Skip()
        
        
    def OnButton(self, event):
        self.mainPanel.Refresh()
        if t2 and l2 and button and ashu:
            t2.Destroy()
            l2.Destroy()
            button.Destroy()
            ashu.Destroy()
            mb.Insert(0,file_menu, "&File")
            self.mainPanel.Refresh()
            bitmap = wx.Bitmap(os.path.normpath(bitmapDir+"gradientbutton.png"), wx.BITMAP_TYPE_PNG)
            self.btn2 = GB.GradientButton(self.mainPanel, -1, bitmap, "open drive", pos=(60,130), size=(120,50)) 
            self.btn4 = GB.GradientButton(self.mainPanel, -1, bitmap, "Lock Folder", pos=(420,130), size=(130,50))
            self.btn4.Disable()
            self.button=wx.Button(self.mainPanel,-1,"Finish", pos=(250,250))
            self.button.Enable()
            btn.Disable()
            try:
                decrypt_file(key, "vd.enc")
                os.rename("vd","vd.dll")
            except:
                pass
            leftbottomsizer_staticbox = wx.StaticBox(self.mainPanel, -1, "Open your Drive", pos=(40,70), size=(170,170))
            rightbottomsizer_staticbox = wx.StaticBox(self.mainPanel, -1, "Lock your Drive", pos=(400,70), size=(170,170))
            self.Bind(wx.EVT_BUTTON, self.OnButton2, self.btn2)
            self.Bind(wx.EVT_BUTTON, self.OnButton4, self.btn4)
            self.Bind(wx.EVT_BUTTON, self.OnButtona, self.button)

    def OnButtona(self,event):
        dlg=wx.MessageDialog(None, "Have you locked your drive?",'Quit',wx.YES_NO | wx.ICON_QUESTION)
        retcode=dlg.ShowModal()
        if (retcode==wx.ID_YES):
            os.system("reg delete hklm\\software\\microsoft\\Flk /v oninithold /f")   
            self.Destroy()
        else:
            pass

        

    def OnButton2(self,event):
        self.button.Disable()
        try:
            vd=open("vd.dll","r")
            vdc=vd.read()
            vd.close()
            chk=os.access(vdc,0777)
            if chk:
                os.system("reg add hklm\\software\\microsoft\\Flk /v uponsingleexit /t reg_sz /f")
                os.startfile(vdc)
                self.btn4.Enable()
            else:
                busy = wx.BusyInfo("One moment please, Preparing your drive...\nYour window might be unresponsive.Do not try to close this window")
                wx.Yield()
                decrypt_file(key, "libb.enc")
                os.rename("libb","libb.dll")
                fopl=open("libb.dll","r")
                fopll=fopl.read()
                fopl.close()
                drv=fopll[:3]
                try:
                    accessa=os.access("%slocked"% drv,0777)
                    if accessa:
                        os.rename("%slocked"%drv,"%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"%drv)
                    else:
                        accessb=os.access("%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"%drv,0777)
                        if accessb:
                            pass
                        else:
                            showerror("Error","Software Corrupt!!!\n\nPlease reinstall")
                except:
                    pass
                    
                lib=open("myscr.s","w")
                lib.write("select vdisk file=%s\n" % fopll)
                lib.write("attach vdisk")
                lib.close()
                try:
                    os.rename("%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"% drv,"%slocked"% drv) 
                    os.system("move %slocked\\locker.vhd %s"% (drv, drv))
                    wx.CallAfter(self.LoggMessage,"decrypting")
                    vds=open("vd.dll","r")
                    vdd=vds.read()
                    vds.close()
                    os.system("reg add hklm\\software\\microsoft\\Flk /v uponsingleexit /t reg_sz /f")
                    dlg = wx.MessageDialog(self, "Folder have been prepared successfully.\nIt will be prompted to open.", "Reinstall",
                               wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                except:
                    dlg = wx.MessageDialog(self, "Protected folder could not be found.\nPlease reinstall the software.", "Reinstall",
                               wx.OK | wx.ICON_ERROR)
                    dlg.ShowModal()
                    dlg.Destroy()
                    
                
                              
        except:
            dlg = wx.MessageDialog(self, "vd.dll could not be found.\nPlease reinstall the software.", "Reinstall",
                               wx.OK | wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            
        
    def LoggMessage(self, event):
        os.system("diskpart /s myscr.s")
        os.remove("myscr.s")
        self.btn4.Enable()


    def OnButton4(self,event):
        try:
            self.btn4.Disable()
        except:
            pass
        self.btn2.Destroy()
        mb.Remove(0)
        self.mainPanel.Refresh()
        try:
            decrypt_file(key, "libb.enc")
            os.rename("libb","libb.dll")
            fopl=open("libb.dll","r")
            fopll=fopl.read()
            fopl.close()
            drv=fopll[:3]
            os.remove("libb.dll")
            popl=os.access("%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"%drv,0777)
            if popl:
                dlg = wx.MessageDialog(self, "File already locked", "Encrypted",
                               wx.OK | wx.ICON_INFORMATION)
                dlg.ShowModal()
                dlg.Destroy()
                sys.exit()
            else:
                pass
        except:
            os.remove("libb")
            pass
        
        wx.CallAfter(self.mymessage, "i m back")
        ppa=wx.StaticText(self.mainPanel, -1, "Folder Locked",(60, 170))
        self.button.Enable()
        
    def mymessage(self,event):
        busy = wx.BusyInfo("One moment please, Encrypting your drive...\nYour window might be unresponsive.Do not try to close this window")
        wx.Yield()
        try:
            busy = wx.BusyInfo("One moment please, Preparing your drive...\nYour window might be unresponsive.Do not try to close this window")
            wx.Yield()
            fopl=open("libb.dll","r")
            fopll=fopl.read()
            fopl.close()
            os.remove("libb.dll")
            drvs=fopll[:3]
            decrypt_file(key, "mysc.enc")
            os.rename("mysc","myscra.s")
            os.system("diskpart /s myscra.s")
            os.system("move %slocker.vhd %slocked\\"%(drvs, drvs))
            os.system("cls")
            os.rename("%slocked\\"% drvs,"%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"% drvs)
            os.system("attrib %slocked.{645FF040-5081-101B-9F08-00AA002F954E} +s +h +r +a"%drvs)
            os.system("reg delete hklm\\software\\microsoft\\Flk /v oninithold /f")
            os.system("reg delete hklm\\software\\microsoft\\Flk /v uponsingleexit /f")
            os.remove("myscra.s")
            os.remove("vd.dll")
            try:
                os.remove("vd")
            except:
                pass
            
        except:
            dlg = wx.MessageDialog(self, "going to do encryption!!!.", "Success",
                               wx.OK | wx.ICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
            busy = wx.BusyInfo("One moment please, Preparing your drive...\nYour window might be unresponsive.Do not try to close this window")
            wx.Yield()
            decrypt_file(key, "libb.enc")
            os.rename("libb","libb.dll")
            fopl=open("libb.dll","r")
            fopll=fopl.read()
            fopl.close()
            os.remove("libb.dll")
            drvs=fopll[:3]
            fop=open("myscrb.s","w")
            fop.write("select vdisk file=%s\n" % fopll)
            fop.write("detach vdisk")
            fop.close()
            os.system("diskpart /s myscrb.s")
            os.system("move %slocker.vhd %slocked\\"%(drvs, drvs))
            os.system("reg delete hklm\\software\\microsoft\\Flk /v oninithold /f")
            os.system("reg delete hklm\\software\\microsoft\\Flk /v uponsingleexit /f")
            os.system("cls")
            os.rename("%slocked"% drvs,"%slocked.{645FF040-5081-101B-9F08-00AA002F954E}"% drvs)
            os.remove("myscrb.s")

        dlg = wx.MessageDialog(self, "Encryption has been done successfully!!!.", "Success",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()
            
            
            
            



            
        
    def OnSetBarText(self, event):

        dlg = wx.TextEntryDialog(self, "Enter The Text You Wish To Display On The Bar (Clear If No Text):",
                                 "Set Text", self.titleBar.GetBarText())
        
        if dlg.ShowModal() == wx.ID_OK:
        
            val = dlg.GetValue()
            self.titleBar.SetBarText(val)
            self.titleBar.DoLayout()
            self.mainPanel.Layout()


    def OnSettingsPanel(self, event):

        if self.hassettingpanel:
            self.settingspanel.Raise()
            return

        self.settingspanel = SettingsPanel(self, -1)
        self.settingspanel.Show()
        self.hassettingpanel = True


    def OnClose(self, event):
        dlg = wx.MessageDialog(self, "You cannot quit in middle\n\nPlease first complete \nand then quit using 'Finish' button", "Quit",
                               wx.OK | wx.ICON_ERROR)
        dlg.ShowModal()
        dlg.Destroy()
    

    def OnAbout(self, event):

        msg = "I am here to tell me something about me and my software\n\n" + \
              "Developer: Ashutosh Chaudhary @ 27 may 2011\n\n" + \
              "Please Report Any Bug/Requests Of Improvements\n" + \
              "To Me At The Following Adresses:\n\n" + \
              "216.ashutosh@gmail.com\n" + "www.ashurocks.20m.com\n\n" + \
              "Based On python C++ wx Implementation (wxWidgets Forum).\n\n" + \
              "Welcome To Advanced Folder Locker!!"
              
        dlg = wx.MessageDialog(self, msg, "Advanced Folder Locker",
                               wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()        


#----------------------------------------------------------------------

class MyApp(wx.App): 
    def OnInit(self): 
       frame = ButtonPanelDemo(self)
       filea=os.access("def.enc",0777)
       fileb=os.access("libb.enc",0777)
       filec=os.access("vd.enc",0777)
       filed=os.access("mysc.enc",0777)
       if filea and fileb and filec and filed:
           pass
       else:
           dlg = wx.MessageDialog(frame, "Neccessary files not found.\nCould not continue.Exiting....", "Software Corrupt",
                               wx.OK | wx.ICON_ERROR)
           dlg.ShowModal()
           dlg.Destroy()
           sys.exit()
           
       try:
            os.system("reg query hklm\\software\\microsoft\\Flk /v oninithold /t reg_sz >> record.txt 2>&1")
            fipl=open("record.txt","r")
            fips=fipl.readlines()
            fipl.close()
            os.remove("record.txt")
            os.system("reg query hklm\\software\\microsoft\\Flk /v uponsingleexit /t reg_sz >> records.txt 2>&1")
            fippl=open("records.txt","r")
            fipps=fippl.readlines()
            fippl.close()
            os.remove("records.txt")
            qwl=fipps[-1]
            rws=fipps.index(qwl)
            qw=fips[-1]
            rw=fips.index(qw)
            if (rw==4):
                if (rws==4):
                    dlg = wx.MessageDialog(frame, "Your drive is in open state", "Unsercured Breach",
                               wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                    frame.Show()
                else:
                    dlg = wx.MessageDialog(frame, "Your drive is not locked properly", "Unsercured Breach",
                               wx.OK | wx.ICON_INFORMATION)
                    dlg.ShowModal()
                    dlg.Destroy()
                    frame.Show()
            else:
                frame.Show()
       except:
           pass
       self.SetTopWindow(frame) 
       return True





#----------------------------------------------------------------------



overview = bp.__doc__



if __name__ == '__main__':
    app = MyApp(False) 
    app.MainLoop()
    


